﻿package com.amcharts.utils
{
    import com.amcharts.geom.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import mx.core.*;
    import mx.styles.*;

    public class AmSimpleButton extends UIComponent
    {
        private var _bg:Rect;
        private var _label:String;
        private var _originalTransform:ColorTransform;
        private var _icon:Class;
        static const VERSION:String = "1.8.3.1";
        private static var stylesInited:Boolean = initStyles();

        public function AmSimpleButton()
        {
            this.addEventListener(MouseEvent.ROLL_OVER, handleMouseOver);
            this.addEventListener(MouseEvent.ROLL_OUT, handleMouseOut);
            return;
        }// end function

        private function handleMouseOut(event:MouseEvent) : void
        {
            if (_bg)
            {
                _bg.transform.colorTransform = _originalTransform;
                _bg.alpha = this.getStyle("backgroundAlpha");
            }
            return;
        }// end function

        public function set label(param1:String) : void
        {
            _label = param1;
            return;
        }// end function

        private function handleMouseOver(event:MouseEvent) : void
        {
            if (_bg)
            {
                _originalTransform = _bg.transform.colorTransform;
                Utils.setRGB(_bg, this.getStyle("backgroundRollOverColor"));
                _bg.alpha = this.getStyle("backgroundRollOverAlpha");
            }
            return;
        }// end function

        public function set icon(param1:Class) : void
        {
            _icon = param1;
            return;
        }// end function

        public function get label() : String
        {
            return _label;
        }// end function

        override protected function updateDisplayList(param1:Number, param2:Number) : void
        {
            var _loc_5:DisplayObject = null;
            var _loc_6:UITextField = null;
            var _loc_7:UITextFormat = null;
            super.updateDisplayList(param1, param2);
            Utils.removeChildren(this);
            var _loc_3:Number = 0;
            var _loc_4:Number = 0;
            if (_icon)
            {
                _loc_5 = DisplayObject(new _icon());
                _loc_5.x = 5;
                _loc_5.y = 5;
                this.addChild(_loc_5);
                _loc_3 = _loc_5.width + 10;
                _loc_4 = _loc_5.height + 10;
            }
            if (_label)
            {
                _loc_6 = UITextField(createInFontContext(UITextField));
                _loc_7 = determineTextFormatFromStyles();
                _loc_6.height = 0;
                _loc_6.multiline = false;
                _loc_6.wordWrap = false;
                _loc_6.selectable = false;
                _loc_6.width = this.width;
                _loc_6.setTextFormat(_loc_7);
                _loc_6.antiAliasType = _loc_7.antiAliasType;
                _loc_6.gridFitType = _loc_7.gridFitType;
                _loc_6.sharpness = _loc_7.sharpness;
                _loc_6.thickness = _loc_7.thickness;
                if (systemManager)
                {
                }
                _loc_6.embedFonts = systemManager.isFontFaceEmbedded(_loc_7);
                _loc_6.defaultTextFormat = _loc_7;
                _loc_6.htmlText = _label;
                _loc_6.width = _loc_6.textWidth + 5;
                _loc_6.height = _loc_6.textHeight + 3;
                this.addChild(_loc_6);
                if (_icon)
                {
                    _loc_6.x = _loc_5.width + 10;
                }
                else
                {
                    _loc_6.x = 10;
                }
                _loc_6.y = 5;
                _loc_3 = _loc_6.x + _loc_6.width + 9;
                if (_loc_6.height + 10 > _loc_4)
                {
                    _loc_4 = _loc_6.height + 10;
                }
            }
            if (_loc_4 > 0)
            {
            }
            if (_loc_3 > 0)
            {
                _bg = new Rect(_loc_3, _loc_4, [this.getStyle("backgroundColor")], [1]);
                _bg.alpha = this.getStyle("backgroundAlpha");
                this.addChildAt(_bg, 0);
            }
            this.width = _loc_3;
            this.height = _loc_4;
            return;
        }// end function

        private static function initStyles() : Boolean
        {
            var styleDeclaration:* = StyleManager.getStyleDeclaration("AmSimpleButton");
            if (!styleDeclaration)
            {
                styleDeclaration = new CSSStyleDeclaration();
            }
            styleDeclaration.defaultFactory = function () : void
            {
                this.backgroundRollOverColor = 11723263;
                this.backgroundRollOverAlpha = 1;
                this.backgroundColor = 16777215;
                this.backgroundAlpha = 0;
                return;
            }// end function
            ;
            StyleManager.setStyleDeclaration("AmSimpleButton", styleDeclaration, false);
            return true;
        }// end function

    }
}
